import { iconDatabase, iconHome } from "./fluent";
import { h } from "vue";
import { NIcon } from "naive-ui";

export const iconMap: Map<string, any> = new Map<string, any>();

export function initIconMap() {
  iconMap.set("home", iconHome);
  iconMap.set("database", iconDatabase);
}

export function icon(name: string): any {
  if (iconMap.has(name)) {
    return iconMap.get(name);
  } else {
    return null;
  }
}

export function renderIconByName(name: string) {
  const i = icon(name);
  if (i === null) {
    return () => h("p");
  } else {
    return renderIcon(i);
  }
}

export function renderIcon(icon: any) {
  return () => h(NIcon, null, { default: () => h(icon) });
}
